import React, { ReactElement, useEffect, useState } from "react";
import TransitTime from "../../components/TransitTime";
import {TransitTimeInfo} from "../../types";
import {EQS} from '../../models'
const ItemInformation = (): ReactElement => {
  var [transitTimes, setTransitTime] = useState<TransitTimeInfo[]>([]);

  useEffect(() => {
    fetch("https://localhost:5001/api/React/GetAll")
    .then(res => res.json())
    .then(
      (result:TransitTimeInfo[]) => {
        console.log(result);
        setTransitTime(result);
      },

      (error) => {
        ;
      }
    )
    return () => {
      ;
    }
  }, []);

  const addTransitTime = (item:TransitTimeInfo) => {
    setTransitTime([...transitTimes, item]);
  };

  const removeTransitTime = (id:string):void => {
    setTransitTime(transitTimes.filter(ent=>ent.id!==id));
  };

  return (
    <>
      <TransitTime
        transitTimes={transitTimes}
        addTransitTime={addTransitTime}
        removeTransitTime={removeTransitTime}
      ></TransitTime>
    </>
  );
};

export default ItemInformation;